package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hulk.ratel.common.constant.enums.UseFlag;
import com.hulk.ratel.common.constant.enums.YesOrNo;
import com.hulk.ratel.persistence.entity.PartnerKey;
import com.hulk.ratel.persistence.repository.IPartnerKeyRepository;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * Created by hulk on 2017/11/22.
 * 合作方密钥配置
 */
@Slf4j
@Component
public class PartnerKeyCache {

    @Autowired
    private IPartnerKeyRepository partnerKeyRepository;

    /**
     * 合作方密钥查询
     *
     * @param partnerNo
     * @return
     */

    //@Cacheable(value = "partnerKeyCache", key = "#partnerNo + 'PartnerKeyCache_findPartnerKey'")
    @Cached(key = "#partnerNo  + 'PartnerKeyCache_findPartnerKey'", cacheType = CacheType.LOCAL ,expire =600)
    public PartnerKey findPartnerKey(@NonNull String partnerNo) {
        PartnerKey key = new PartnerKey();
        key.setPartnerNo(partnerNo);
        key.setArchivedFlag(YesOrNo.NO.getValue());
        key.setAuditedFlag(YesOrNo.YES.getValue());
        key.setUseFlag(UseFlag.Y.getValue());
        Wrapper<PartnerKey> query = new QueryWrapper<>(key);
        return partnerKeyRepository.getOne(query);
    }
}
